﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebApp._Management._Content
{
    public partial class ContentList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadContents();
        }

        private void LoadContents()
        {
            string path = Server.MapPath("~/_Contents/");
            string[] files = Directory.GetFiles(path);

            List<FileStruct> fileList = new List<FileStruct>();
            foreach (string item in files)
            {
                fileList.Add(new FileStruct
                {
                    Name = item,
                    Path = item
                });
            }

            this._ctlRepeaterFiles.DataSource = fileList;
            this._ctlRepeaterFiles.DataBind();
        }

        protected void _ctlBtnUpload_Click(object sender, EventArgs e)
        {
            string folder = Server.MapPath(string.Format("~/_Contents/{0}", _ctlEditPath.Text));
            _ctlFileUpload.SaveAs(Path.Combine(folder, _ctlFileUpload.FileName));
            Response.Write("<script>alert('上传成功!');window.location.href=window.location.href;</script>");
        }
    }

    public class FileStruct
    {
        public string Name { get; set; }
        public string Path { get; set; }
    }
}